package com.ruoyi.web.controller.meeting;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.meeting.domain.SysMeeting;
import com.ruoyi.meeting.domain.SysMeetingAttendee;
import com.ruoyi.meeting.service.ISysMeetingService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 会议管理Controller
 * 
 * @author ruoyi
 * @date 2025-01-27
 */
@RestController
@RequestMapping("/meeting/meeting")
public class SysMeetingController extends BaseController
{
    @Autowired
    private ISysMeetingService sysMeetingService;

    /**
     * 查询会议管理列表
     */
    @PreAuthorize("@ss.hasPermi('meeting:meeting:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysMeeting sysMeeting)
    {
        startPage();
        List<SysMeeting> list = sysMeetingService.selectSysMeetingList(sysMeeting);
        return getDataTable(list);
    }

    /**
     * 导出会议管理列表
     */
    @PreAuthorize("@ss.hasPermi('meeting:meeting:export')")
    @Log(title = "会议管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysMeeting sysMeeting)
    {
        List<SysMeeting> list = sysMeetingService.selectSysMeetingList(sysMeeting);
        ExcelUtil<SysMeeting> util = new ExcelUtil<SysMeeting>(SysMeeting.class);
        util.exportExcel(response, list, "会议管理数据");
    }

    /**
     * 获取会议管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('meeting:meeting:query')")
    @GetMapping(value = "/{meetingId}")
    public AjaxResult getInfo(@PathVariable("meetingId") Long meetingId)
    {
        return success(sysMeetingService.selectSysMeetingByMeetingId(meetingId));
    }

    /**
     * 新增会议管理
     */
    @PreAuthorize("@ss.hasPermi('meeting:meeting:add')")
    @Log(title = "会议管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysMeeting sysMeeting)
    {
        sysMeeting.setCreateBy(getUsername());
        return toAjax(sysMeetingService.insertSysMeeting(sysMeeting));
    }

    /**
     * 修改会议管理
     */
    @PreAuthorize("@ss.hasPermi('meeting:meeting:edit')")
    @Log(title = "会议管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysMeeting sysMeeting)
    {
        sysMeeting.setUpdateBy(getUsername());
        return toAjax(sysMeetingService.updateSysMeeting(sysMeeting));
    }

    /**
     * 删除会议管理
     */
    @PreAuthorize("@ss.hasPermi('meeting:meeting:remove')")
    @Log(title = "会议管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{meetingIds}")
    public AjaxResult remove(@PathVariable Long[] meetingIds)
    {
        return toAjax(sysMeetingService.deleteSysMeetingByMeetingIds(meetingIds));
    }

    /**
     * 查询今日会议列表
     */
    @GetMapping("/today")
    public AjaxResult getTodayMeetings()
    {
        List<SysMeeting> list = sysMeetingService.selectTodayMeetingList();
        return success(list);
    }

    /**
     * 查询即将开始的会议列表
     */
    @GetMapping("/upcoming")
    public AjaxResult getUpcomingMeetings()
    {
        List<SysMeeting> list = sysMeetingService.selectUpcomingMeetingList();
        return success(list);
    }

    /**
     * 获取会议参会人员列表
     */
    @GetMapping("/attendees/{meetingId}")
    public AjaxResult getAttendeesByMeetingId(@PathVariable Long meetingId)
    {
        List<SysMeetingAttendee> attendees = sysMeetingService.selectAttendeesByMeetingId(meetingId);
        return success(attendees);
    }

    /**
     * 添加参会人员
     */
    @PreAuthorize("@ss.hasPermi('meeting:meeting:edit')")
    @Log(title = "添加参会人员", businessType = BusinessType.INSERT)
    @PostMapping("/addAttendee")
    public AjaxResult addAttendee(@RequestBody SysMeetingAttendee sysMeetingAttendee)
    {
        return toAjax(sysMeetingService.addAttendee(sysMeetingAttendee));
    }

    /**
     * 会议签到
     */
    @Log(title = "会议签到", businessType = BusinessType.UPDATE)
    @PostMapping("/signIn/{id}")
    public AjaxResult signIn(@PathVariable Long id)
    {
        return toAjax(sysMeetingService.signIn(id));
    }

    /**
     * 开始会议
     */
    @PreAuthorize("@ss.hasPermi('meeting:meeting:edit')")
    @Log(title = "开始会议", businessType = BusinessType.UPDATE)
    @PostMapping("/start/{meetingId}")
    public AjaxResult startMeeting(@PathVariable Long meetingId)
    {
        return toAjax(sysMeetingService.startMeeting(meetingId));
    }

    /**
     * 结束会议
     */
    @PreAuthorize("@ss.hasPermi('meeting:meeting:edit')")
    @Log(title = "结束会议", businessType = BusinessType.UPDATE)
    @PostMapping("/end/{meetingId}")
    public AjaxResult endMeeting(@PathVariable Long meetingId)
    {
        return toAjax(sysMeetingService.endMeeting(meetingId));
    }

    /**
     * 统计会议参会人数
     */
    @GetMapping("/countAttendees/{meetingId}")
    public AjaxResult countAttendees(@PathVariable Long meetingId)
    {
        int count = sysMeetingService.countAttendeesByMeetingId(meetingId);
        return success(count);
    }

    /**
     * 统计会议签到人数
     */
    @GetMapping("/countSignedIn/{meetingId}")
    public AjaxResult countSignedIn(@PathVariable Long meetingId)
    {
        int count = sysMeetingService.countSignedInByMeetingId(meetingId);
        return success(count);
    }
}
